package com.hong.spring.sepl;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class ScriptSample {
    public static void main(String[] args) throws Exception {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        String scriptText = "function sum(a,b){return a+b}";
        engine.eval(scriptText);
        Invocable invocable = (Invocable)engine;
        Object result = invocable.invokeFunction("sum", 1, 2);
        System.out.println(result);
    }

}
